home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / config.h < prev    next >
C/C++ Source or Header  |  2000-01-16  |  27KB  |  921 lines

  1. // $Id: config.h,v 1.32 2000/01/06 08:45:44 lord Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef config_INCLUDED
  11. #define config_INCLUDED
  12.  
  13. #ifdef HAVE_WCHAR_H
  14. # include <wchar.h>
  15. #endif
  16.  
  17. #ifndef HAVE_WINT_T
  18.     /* On some systems the type wint_t is not defined in wchar.h */
  19.     typedef unsigned int wint_t;
  20. #endif
  21. #include <new.h>
  22. #include <iostream.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <assert.h>
  26. #include <string.h>
  27. #include <stdio.h>
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30.  
  31.  
  32. #if defined(GNU_LIBC5)
  33.     extern size_t wcslen(wchar_t *);
  34.     extern wchar_t *wcscpy(wchar_t *, wchar_t *);
  35.     extern wchar_t *wcsncpy(wchar_t *, wchar_t *, int);
  36.     extern wchar_t *wcscat(wchar_t *, wchar_t *);
  37.     extern int wcscmp(wchar_t *, wchar_t *);
  38.     extern int wcsncmp(wchar_t *, wchar_t *, int);
  39. #endif
  40.  
  41.  
  42. #ifdef TEST
  43. #define NO_LEAKS
  44. #endif
  45.  
  46. //
  47. // We need to set up certain environment information depending on
  48. // the host OS.
  49. //
  50. // Jikes uses the stat() system call to query file status. Traditional
  51. // unix systems use S_IFDIR and S_IFREG as names for constants used to
  52. // see if file is directory or regular file, respectively. POSIX-based
  53. // systems use __S_IFDIR and __S_IFREG, with S_IFDIR and S_IFREG being
  54. // defined as macros
  55. //
  56. #ifdef STAT_POSIX
  57. #define STAT_S_IFDIR __S_IFDIR
  58. #define STAT_S_IFREG __S_IFREG
  59. #else
  60. #define STAT_S_IFDIR S_IFDIR
  61. #define STAT_S_IFREG S_IFREG
  62. #endif
  63.  
  64. #ifdef STAT_POSIX_1
  65. // Some variants of HPUX want just one underscore
  66. #undef STAT_S_IFDIR
  67. #undef STAT_S_IFREG
  68. #define STAT_S_IFDIR _S_IFDIR
  69. #define STAT_S_IFREG _S_IFREG
  70. #endif
  71. //
  72. // These definitions are correct for all the platforms that
  73. // we are currently using. When porting this code, they should
  74. // always be reviewed.
  75. //
  76. #include <limits.h>
  77.  
  78. #ifdef BROKEN_USHRT_MAX
  79.     /* There is a bug in mingwin's limits.h file we need to work around */
  80. # undef USHRT_MAX
  81. # ifdef SHRT_MAX
  82. #  define USHRT_MAX (2U * SHRT_MAX + 1)
  83. # else
  84. #  define USHRT_MAX 0xFFFF
  85. # endif
  86. #endif
  87.  
  88. #if ! (UINT_MAX == 0xFFFFFFFF)
  89. #error unsigned int does not store values in the range 0..4294967295 in this system
  90. #else
  91.     typedef unsigned int u4;
  92. #endif
  93.  
  94. #if ! ((INT_MAX == 2147483647) && (INT_MIN + 1 == -INT_MAX))
  95. #error signed int does not store values in the range -2147483648..+2147483647 in this system
  96. #else
  97.     typedef signed int i4;
  98. #endif
  99.  
  100. #if ! (USHRT_MAX == 0xFFFF)
  101. #error unsigned short does not store values in the range 0..65535 in this system
  102. #else
  103.     typedef unsigned short u2;
  104. #endif
  105.  
  106. #if ! ((SHRT_MAX == 32767) && (SHRT_MIN + 1 == -SHRT_MAX))
  107. #error signed short does not store values in the range -32767..+32768 in this system
  108. #else
  109.     typedef signed short i2;
  110. #endif
  111.  
  112. #if ! (UCHAR_MAX == 0xFF)
  113. #error unsigned char does not store values in the range 0..255 in this system
  114. #else
  115.     typedef unsigned char u1;
  116. #endif
  117.  
  118. #if ! ((SCHAR_MAX == 127) && (SCHAR_MIN + 1 == -SCHAR_MAX))
  119. #error signed character does not store values in the range -128..+127 in this system
  120. #else
  121.     typedef signed char i1;
  122. #endif
  123.  
  124. enum U_chars
  125. {
  126.     U_NULL = 0,               U_NU = U_NULL,            // L'\0'
  127.     U_BACKSPACE = 8,          U_BS = U_BACKSPACE,       // L'\b'
  128.     U_HORIZONTAL_TAB = 9,     U_HT = U_HORIZONTAL_TAB,  // L'\t'
  129.     U_LINE_FEED = 10,         U_LF = U_LINE_FEED,       // L'\n'
  130.     U_FORM_FEED = 12,         U_FF = U_FORM_FEED,       // L'\f'
  131.     U_CARRIAGE_RETURN = 13,   U_CR = U_CARRIAGE_RETURN, // L'\r'
  132.  
  133.     U_CTL_Z = 26,
  134.     U_ESCAPE = 27,
  135.  
  136.     U_SPACE = 32,             U_SP = U_SPACE,             // L' '
  137.     U_EXCLAMATION = 33,       U_EX = U_EXCLAMATION,       // L'!'
  138.     U_DOUBLE_QUOTE = 34,      U_DQ = U_DOUBLE_QUOTE,      // L'"'
  139.     U_POUND = 35,             U_SH = U_POUND,             // L'#'
  140.     U_DOLLAR = 36,            U_DS = U_DOLLAR,            // L'$'
  141.     U_PERCENT = 37,           U_PE = U_PERCENT,           // L'%'
  142.     U_AMPERSAND = 38,         U_AM = U_AMPERSAND,         // L'&'
  143.     U_SINGLE_QUOTE = 39,      U_SQ = U_SINGLE_QUOTE,      // L'\''
  144.     U_LEFT_PARENTHESIS = 40,  U_LP = U_LEFT_PARENTHESIS,  // L'('
  145.     U_RIGHT_PARENTHESIS = 41, U_RP = U_RIGHT_PARENTHESIS, // L')'
  146.     U_STAR = 42,              U_ST = U_STAR,              // L'*'
  147.     U_PLUS = 43,              U_PL = U_PLUS,              // L'+'
  148.     U_MINUS = 45,             U_MI = U_MINUS,             // L'-'
  149.     U_COMMA = 44,             U_CM = U_COMMA,             // L','
  150.     U_DOT = 46,               U_DO = U_DOT,               // L'.'
  151.     U_SLASH = 47,             U_SL = U_SLASH,             // L'/'
  152.  
  153.     U_0 = 48, // L'0'
  154.     U_1 = 49, // L'1'
  155.     U_2 = 50, // L'2'
  156.     U_3 = 51, // L'3'
  157.     U_4 = 52, // L'4'
  158.     U_5 = 53, // L'5'
  159.     U_6 = 54, // L'6'
  160.     U_7 = 55, // L'7'
  161.     U_8 = 56, // L'8'
  162.     U_9 = 57, // L'9'
  163.  
  164.     U_COLON = 58,             U_CO = U_COLON,     // L':'
  165.     U_SEMICOLON = 59,         U_SC = U_SEMICOLON, // L';'
  166.     U_LESS = 60,              U_LT = U_LESS,      // L'<'
  167.     U_EQUAL = 61,             U_EQ = U_EQUAL,     // L'='
  168.     U_GREATER = 62,           U_GT = U_GREATER,   // L'>'
  169.     U_QUESTION = 63,          U_QU = U_QUESTION,  // L'?'
  170.     U_AT = 64,                                    // L'@'
  171.  
  172.     U_A = 65, // L'A'
  173.     U_B = 66, // L'B'
  174.     U_C = 67, // L'C'
  175.     U_D = 68, // L'D'
  176.     U_E = 69, // L'E'
  177.     U_F = 70, // L'F'
  178.     U_G = 71, // L'G'
  179.     U_H = 72, // L'H'
  180.     U_I = 73, // L'I'
  181.     U_J = 74, // L'J'
  182.     U_K = 75, // L'K'
  183.     U_L = 76, // L'L'
  184.     U_M = 77, // L'M'
  185.     U_N = 78, // L'N'
  186.     U_O = 79, // L'O'
  187.     U_P = 80, // L'P'
  188.     U_Q = 81, // L'Q'
  189.     U_R = 82, // L'R'
  190.     U_S = 83, // L'S'
  191.     U_T = 84, // L'T'
  192.     U_U = 85, // L'U'
  193.     U_V = 86, // L'V'
  194.     U_W = 87, // L'W'
  195.     U_X = 88, // L'X'
  196.     U_Y = 89, // L'Y'
  197.     U_Z = 90, // L'Z'
  198.  
  199.     U_LEFT_BRACKET = 91,      U_LB = U_LEFT_BRACKET,  // L'['
  200.     U_BACKSLASH = 92,         U_RS = U_BACKSLASH,     // L'\\'
  201.     U_RIGHT_BRACKET = 93,     U_RB = U_RIGHT_BRACKET, // L']'
  202.     U_CARET = 94,             U_CA = U_CARET,         // L'^'
  203.     U_UNDERSCORE = 95,        U_UN = U_UNDERSCORE,    // L'_'
  204.  
  205.     U_a = 97, // L'a'
  206.     U_b = 98, // L'b'
  207.     U_c = 99, // L'c'
  208.     U_d = 100, // L'd'
  209.     U_e = 101, // L'e'
  210.     U_f = 102, // L'f'
  211.     U_g = 103, // L'g'
  212.     U_h = 104, // L'h'
  213.     U_i = 105, // L'i'
  214.     U_j = 106, // L'j'
  215.     U_k = 107, // L'k'
  216.     U_l = 108, // L'l'
  217.     U_m = 109, // L'm'
  218.     U_n = 110, // L'n',
  219.     U_o = 111, // L'o'
  220.     U_p = 112, // L'p'
  221.     U_q = 113, // L'q'
  222.     U_r = 114, // L'r'
  223.     U_s = 115, // L's'
  224.     U_t = 116, // L't'
  225.     U_u = 117, // L'u'
  226.     U_v = 118, // L'v'
  227.     U_w = 119, // L'w'
  228.     U_x = 120, // L'x'
  229.     U_y = 121, // L'y'
  230.     U_z = 122, // L'z'
  231.  
  232.     U_LEFT_BRACE = 123,       U_OS = U_LEFT_BRACE,  // L'{'
  233.     U_BAR = 124,              U_BA = U_BAR,         // L'|'
  234.     U_RIGHT_BRACE = 125,      U_CS = U_RIGHT_BRACE, // L'}'
  235.     U_TILDE = 126,            U_TI = U_TILDE,       // L'~'
  236.  
  237.     U_chars_size
  238. };
  239.  
  240.  
  241. //
  242. // Constant strings used in the program.
  243. //
  244. class StringConstant
  245. {
  246. public:
  247.     static wchar_t US_AND[], // "&"
  248.                    US_AND_AND[], // "&&"
  249.                    US_AND_EQUAL[], // "&="
  250.                    US_COLON[], // ":"
  251.                    US_COMMA[], // ","
  252.                    US_DIVIDE[], // "/"
  253.                    US_DIVIDE_EQUAL[], // "/="
  254.                    US_DOT[], // "."
  255.                    US_EMPTY[], // ""
  256.                    US_EQUAL[], // "="
  257.                    US_EQUAL_EQUAL[], // "=="
  258.                    US_GREATER[], // ">"
  259.                    US_GREATER_EQUAL[], // ">="
  260.                    US_LBRACE[], // "{"
  261.                    US_LBRACKET[], // "["
  262.                    US_LEFT_SHIFT[], // "<<"
  263.                    US_LEFT_SHIFT_EQUAL[], // "<<="
  264.                    US_LESS[], // "<"
  265.                    US_LESS_EQUAL[], // "<="
  266.                    US_LPAREN[], // "("
  267.                    US_MINUS[], // "-"
  268.                    US_MINUS_EQUAL[], // "-="
  269.                    US_MINUS_MINUS[], // "--"
  270.                    US_MULTIPLY[], // "*"
  271.                    US_MULTIPLY_EQUAL[], // "*="
  272.                    US_NOT[], // "!"
  273.                    US_NOT_EQUAL[], // "!="
  274.                    US_OR[], // "|"
  275.                    US_OR_EQUAL[], // "|="
  276.                    US_OR_OR[], // "||"
  277.                    US_PLUS[], // "+"
  278.                    US_PLUS_EQUAL[], // "+="
  279.                    US_PLUS_PLUS[], // "++"
  280.                    US_QUESTION[], // "?"
  281.                    US_RBRACE[], // "}"
  282.                    US_RBRACKET[], // "]"
  283.                    US_REMAINDER[], // "%"
  284.                    US_REMAINDER_EQUAL[], // "%="
  285.                    US_RIGHT_SHIFT[], // ">>"
  286.                    US_RIGHT_SHIFT_EQUAL[], // ">>="
  287.                    US_RPAREN[], // ")"
  288.                    US_SEMICOLON[], // ";"
  289.                    US_TWIDDLE[], // "~"
  290.                    US_UNSIGNED_RIGHT_SHIFT[], // ">>>"
  291.                    US_UNSIGNED_RIGHT_SHIFT_EQUAL[], // ">>>="
  292.                    US_XOR[], // "^"
  293.                    US_XOR_EQUAL[], // "^="
  294.  
  295.                    US_Boolean[], // "Boolean"
  296.                    US_Byte[], // "Byte"
  297.                    US_Character[], // "Character"
  298.                    US_Class[], // "Class"
  299.                    US_ClassNotFoundException[], // "ClassNotFoundException"
  300.                    US_Cloneable[], // "Cloneable"
  301.                    US_Double[], // "Double"
  302.                    US_Error[], // "Error"
  303.                    US_Exception[], // "Exception"
  304.                    US_Float[],  // "Float"
  305.                    US_Integer[], // "Integer"
  306.                    US_L[], // "L"
  307.                    US_Long[], // "Long"
  308.                    US_NoClassDefFoundError[], // "NoClassDefFoundError"
  309.                    US_Object[], // "Object"
  310.                    US_PObject[], // "PObject"
  311.                    US_RuntimeException[], // "RuntimeException"
  312.                    US_Serializable[], // "Serializable"
  313.                    US_Short[], // "Short"
  314.                    US_StringBuffer[], // "StringBuffer"
  315.                    US_String[], // "String"
  316.                    US_TYPE[], // "TYPE"
  317.                    US_Vector[], // Vector
  318.                    US_Throwable[], // "Throwable"
  319.                    US_Void[], // "Void"
  320.                    US__DO[], // "."
  321.                    US__DO__DO[], // ".."
  322.                    US__DS[], // "$"
  323.                    US__LB__RB[], // "[]"
  324.                    US__LT_clinit_GT[], // "<clinit>"
  325.                    US__LT_init_GT[], // "<init>"
  326.                    US__QU__QU[],  // "??"
  327.                    US__SC[], // ";"
  328.                    US__SL[], // "/"
  329.  
  330.                    US__zip[], // "zip"
  331.                    US__jar[], // "jar"
  332.  
  333.                    US__array[], // "array"
  334.                    US__access_DOLLAR[], // "access$"
  335.                    US__class_DOLLAR[], // "class$"
  336.                    US__constructor_DOLLAR[], // "constructor$"
  337.                    US__this_DOLLAR[], // "this$"
  338.                    US__val_DOLLAR[], // "val$"
  339.  
  340.                    US_abstract[], // "abstract"
  341.                    US_append[], // "append"
  342.                    US_block_DOLLAR[], // "block$"
  343.                    US_boolean[], // "boolean"
  344.                    US_break[], // "break"
  345.                    US_byte[], // "byte"
  346.                    US_case[], // "case"
  347.                    US_catch[], // "catch"
  348.                    US_char[], // "char"
  349.                    US_class[], // "class"
  350.                    US_clone[], // "clone"
  351.                    US_const[], // "const"
  352.                    US_continue[], // "continue"
  353.                    US_default[], // "default"
  354.                    US_do[], // "do"
  355.                    US_double[], // "double"
  356.                    US_else[], // "else"
  357.                    US_extends[], // "extends"
  358.                    US_false[], // "false"
  359.                    US_final[], // "final"
  360.                    US_finally[], // "finally"
  361.                    US_float[], // "float"
  362.                    US_for[], // "for"
  363.                    US_forName[], // "forName"
  364.                    US_getMessage[], // "getMessage"
  365.                    US_goto[], // "goto"
  366.                    US_if[], // "if"
  367.                    US_implements[], // "implements"
  368.                    US_import[], // "import"
  369.                    US_instanceof[], // "instanceof"
  370.                    US_int[], // "int"
  371.                    US_interface[], // "interface"
  372.                    US_java_SL_io[], // "java/io"
  373.                    US_java_SL_lang[], // "java/lang"
  374.                    US_java_SL_util[], // "java/util"
  375.                    US_length[], // "length"
  376.                    US_long[], // "long"
  377.                    US_native[], // "native"
  378.                    US_new[], // "new"
  379.                    US_null[], // "null"
  380.                    US_package[], // "package"
  381.                    US_private[], // "private"
  382.                    US_protected[], // "protected"
  383.                    US_public[], // "public"
  384.                    US_return[], // "return"
  385.                    US_short[], // "short"
  386.                    US_static[], // "static"
  387.                    US_strictfp[], // "strictfp"
  388.                    US_super[], // "super"
  389.                    US_switch[], // "switch"
  390.                    US_synchronized[], // "synchronized"
  391.                    US_this0[], // "this$0"
  392.                    US_this[], // "this"
  393.                    US_throw[], // "throw"
  394.                    US_throws[], // "throws"
  395.                    US_toString[], // "toString"
  396.                    US_transient[], // "transient"
  397.                    US_true[], // "true"
  398.                    US_try[], // "try"
  399.                    US_void[], // "void"
  400.                    US_volatile[], // "volatile"
  401.                    US_while[], // "while"
  402.  
  403.                    US_EOF[]; // "EOF"
  404.  
  405.     static wchar_t US_smallest_int[]; // "-2147483648"
  406.  
  407.     static char U8S_command_format[];
  408.  
  409.     static int U8S_ConstantValue_length,
  410.                U8S_Exceptions_length,
  411.                U8S_InnerClasses_length,
  412.                U8S_Synthetic_length,
  413.                U8S_Deprecated_length,
  414.                U8S_LineNumberTable_length,
  415.                U8S_LocalVariableTable_length,
  416.                U8S_Code_length,
  417.                U8S_Sourcefile_length,
  418.  
  419.                U8S_null_length,
  420.                U8S_this_length;
  421.  
  422.     static char U8S_B[], // "B"
  423.                 U8S_C[], // "C"
  424.                 U8S_Code[], // "Code"
  425.                 U8S_ConstantValue[], // "ConstantValue"
  426.                 U8S_D[], // "D"
  427.                 U8S_Exceptions[], // "Exceptions"
  428.                 U8S_F[], // "F"
  429.                 U8S_I[], // "I"
  430.                 U8S_InnerClasses[], // "InnerClasses"
  431.                 U8S_J[],  // "J"
  432.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_Ljava_SL_lang_SL_Class_SC[], // "(Ljava/lang/String;)Ljava/lang/Class;"
  433.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_V[], // "(Ljava/lang/String;)V"
  434.                 U8S_LP_RP_Ljava_SL_lang_SL_String_SC[], // "()Ljava/lang/String;"
  435.                 U8S_LP_RP_V[], // "()V"
  436.                 U8S_LineNumberTable[], // "LineNumberTable"
  437.                 U8S_LocalVariableTable[], // "LocalVariableTable"
  438.                 U8S_S[], // "S"
  439.                 U8S_Sourcefile[], // "Sourcefile"
  440.                 U8S_Synthetic[], // "Synthetic"
  441.                 U8S_Deprecated[], // "Deprecated"
  442.                 U8S_V[], // "V"
  443.                 U8S_Z[], // "Z"
  444.  
  445.                 U8S__DO[], // "."
  446.                 U8S__DO_class[], // ".class"
  447.                 U8S__DO_java[], // ".java"
  448.                 U8S__DO_tok[], // ".tok"
  449.                 U8S__DO_u[], // ".u"
  450.                 U8S__LP[], // "("
  451.                 U8S__RP[], // ")"
  452.                 U8S__SL[], // "/"
  453.                 U8S__ST[], // "*"
  454.  
  455.                 U8S_class[], // "class"
  456.                 U8S_java[], // "java"
  457.                 U8S_java_SL_lang_SL_ClassNotFoundException[], // "java/lang/ClassNotFoundException"
  458.                 U8S_java_SL_lang_SL_Class[], // "java/lang/Class"
  459.                 U8S_java_SL_lang_SL_InternalError[], // "java/lang/InternalError"
  460.                 U8S_java_SL_lang_SL_NoClassDefFoundError[], // "java/lang/NoClassDefFoundError"
  461.                 U8S_java_SL_lang_SL_StringBuffer[], // "java/lang/StringBuffer"
  462.                 U8S_java_SL_lang_SL_Throwable[], // "java/lang/Throwable"
  463.                 U8S_null[], // "null"
  464.                 U8S_quit[], // "quit"
  465.                 U8S_this[], // "this"
  466.  
  467.                 U8S_LP_LB_C_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "([C)Ljava/lang/StringBuffer;"
  468.                 U8S_LP_C_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(C)Ljava/lang/StringBuffer;"
  469.                 U8S_LP_Z_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(Z)Ljava/lang/StringBuffer;"
  470.                 U8S_LP_I_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(I)Ljava/lang/StringBuffer;"
  471.                 U8S_LP_J_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(J)Ljava/lang/StringBuffer;"
  472.                 U8S_LP_F_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(F)Ljava/lang/StringBuffer;"
  473.                 U8S_LP_D_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(D)Ljava/lang/StringBuffer;"
  474.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(Ljava/lang/String;)Ljava/lang/StringBuffer;"
  475.                 U8S_LP_Ljava_SL_lang_SL_Object_SC_RP_Ljava_SL_lang_SL_StringBuffer_SC[]; // "(Ljava/lang/Object;)Ljava/lang/StringBuffer;"
  476.  
  477.     static char U8S_smallest_int[],      // "-2147483648"
  478.                 U8S_smallest_long_int[]; // "-9223372036854775808"
  479. };
  480.  
  481.  
  482. //
  483. // Convert an integer to its character string representation.
  484. //
  485. class IntToString
  486. {
  487. public:
  488.     IntToString(int);
  489.  
  490.     char *String() { return str; }
  491.     int Length()   { return (&info[TAIL_INDEX]) - str; }
  492.  
  493. private:
  494.     enum { TAIL_INDEX = 1 + 10 }; // 1 for sign, +10 significant digits
  495.  
  496.     char info[TAIL_INDEX + 1], // +1 for '\0'
  497.          *str;
  498. };
  499.  
  500.  
  501. //
  502. // Same as IntToString for wide strings
  503. //
  504. class IntToWstring
  505. {
  506. public:
  507.     IntToWstring(int);
  508.  
  509.     wchar_t *String() { return wstr; }
  510.     int Length()      { return (&winfo[TAIL_INDEX]) - wstr; }
  511.  
  512. private:
  513.     enum { TAIL_INDEX = 1 + 10 }; // 1 for sign, +10 significant digits
  514.  
  515.     wchar_t winfo[TAIL_INDEX + 1], // 1 for sign, +10 significant digits + '\0'
  516.             *wstr;
  517. };
  518.  
  519.  
  520. //
  521. // Convert an unsigned Long integer to its character string representation in decimal.
  522. //
  523. class ULongInt;
  524. class ULongToDecString
  525. {
  526. public:
  527.     ULongToDecString(ULongInt &);
  528.  
  529.     char *String() { return str; }
  530.     int Length()   { return (&info[TAIL_INDEX]) - str; }
  531.  
  532. private:
  533.     enum { TAIL_INDEX = 20 }; // 20 significant digits
  534.  
  535.     char info[TAIL_INDEX + 1], // +1 for '\0'
  536.          *str;
  537. };
  538.  
  539.  
  540. //
  541. // Convert a signed or unsigned Long integer to its character string representation in octal.
  542. //
  543. class BaseLong;
  544. class LongToOctString
  545. {
  546. public:
  547.     LongToOctString(BaseLong &);
  548.  
  549.     char *String() { return str + 1; } // +1 to skip initial '0'
  550.     char *StringWithBase() { return str; }
  551.     int Length()   { return (&info[TAIL_INDEX]) - str; }
  552.  
  553. private:
  554.     enum { TAIL_INDEX = 1 + 22 }; // 1 for initial '0', +22 significant digits
  555.  
  556.     char info[TAIL_INDEX + 1], // + 1 for '\0'
  557.          *str;
  558. };
  559.  
  560.  
  561. //
  562. // Convert a signed or unsigned Long integer to its character string representation in hexadecimal.
  563. //
  564. class LongToHexString
  565. {
  566. public:
  567.     LongToHexString(BaseLong &);
  568.  
  569.     char *String() { return str + 2; } // +2 to skip initial "0x"
  570.     char *StringWithBase() { return str; }
  571.     int Length()   { return (&info[TAIL_INDEX]) - str; }
  572.  
  573. private:
  574.     enum { TAIL_INDEX = 1 + 1 + 16 }; // 1 for initial '0', +1 for 'x', + 16 significant digits
  575.  
  576.     char info[TAIL_INDEX + 1], // +1 for '\0'
  577.          *str;
  578. };
  579.  
  580.  
  581. //
  582. // Convert a signed Long integer to its character string representation in decimal.
  583. //
  584. class LongInt;
  585. class LongToDecString
  586. {
  587. public:
  588.     LongToDecString(LongInt &);
  589.  
  590.     char *String() { return str; }
  591.     int Length()   { return (&info[TAIL_INDEX]) - str; }
  592.  
  593. private:
  594.     enum { TAIL_INDEX = 1 + 19 }; // 1 for sign, +19 significant digits
  595.  
  596.     char info[TAIL_INDEX + 1], // + 1 for '\0'
  597.          *str;
  598. };
  599.  
  600. #ifdef __amigaos__
  601. #define AMIGAOS_FILE_SYSTEM
  602. #endif
  603.  
  604. //
  605. // The configure script check each of these to see if we need our own implementation
  606. //
  607.  
  608. #ifndef HAVE_WCSLEN
  609.     extern size_t wcslen(wchar_t *);
  610. #endif
  611.  
  612. #ifndef HAVE_WCSCPY
  613.     extern wchar_t *wcscpy(wchar_t *, wchar_t *);
  614. #endif
  615.  
  616. #ifndef HAVE_WCSNCPY
  617.     extern wchar_t *wcsncpy(wchar_t *, wchar_t *, int);
  618. #endif
  619.  
  620. #ifndef HAVE_WCSCAT
  621.     extern wchar_t *wcscat(wchar_t *, wchar_t *);
  622. #endif
  623.  
  624. #ifndef HAVE_WCSCMP
  625.     extern int wcscmp(wchar_t *, wchar_t *);
  626. #endif
  627.  
  628. #ifndef HAVE_WCSNCMP
  629.     extern int wcsncmp(wchar_t *, wchar_t *, int);
  630. #endif
  631.  
  632.  
  633. //
  634. // Convert an double to its character string representation.
  635. //
  636. class IEEEdouble;
  637. class DoubleToString
  638. {
  639. public:
  640.     DoubleToString(IEEEdouble &);
  641.  
  642.     char *String() { return str; }
  643.     int Length()   { return length; }
  644.  
  645. private:
  646.     enum
  647.     {
  648.         MAXIMUM_PRECISION = 16,
  649.         MAXIMUM_STR_LENGTH = 1 + MAXIMUM_PRECISION + 1 + 4 // +1 for sign, +16 significant digits +1 for ".", +4 for exponent
  650.     };
  651.  
  652.     char str[MAXIMUM_STR_LENGTH + 1]; // +1 for '\0'
  653.     int length;
  654. };
  655.  
  656. //
  657. // Convert an float to its character string representation.
  658. //
  659. class IEEEfloat;
  660. class FloatToString
  661. {
  662. public:
  663.     FloatToString(IEEEfloat &);
  664.  
  665.     char *String() { return str; }
  666.     int Length()   { return length; }
  667.  
  668. private:
  669.     enum
  670.     {
  671.         MAXIMUM_PRECISION = 8,
  672.         MAXIMUM_STR_LENGTH = 1 + MAXIMUM_PRECISION + 1 + 4 // +1 for sign, +8 significant digits +1 for ".", +4 for exponent
  673.     };
  674.  
  675.     char str[MAXIMUM_STR_LENGTH + 1]; // +1 for '\0'
  676.     int length;
  677. };
  678.  
  679. //
  680. // If the system runs out of memory, this function is invoked.
  681. //
  682. void SetNewHandler();
  683. #ifdef MICROSOFT
  684.     extern int OutOfMemory(size_t);
  685. #else
  686.     extern void OutOfMemory();
  687. #endif
  688.  
  689.  
  690. //
  691. // When using the ICC compiler on Win95 or OS/2, we need to disable
  692. // testing for various floating point exceptions. Default behavior
  693. // was causing problems reading some standard class files.
  694. //
  695. extern void FloatingPointCheck();
  696.  
  697.  
  698. //
  699. // variants of system functions
  700. // are declared here and defined in code.cpp
  701. //
  702. extern int SystemStat(const char *name, struct stat *stat_struct);
  703. extern FILE *SystemFopen(char *name, char *mode);
  704. extern size_t SystemFread(char *ptr, size_t element_size, size_t count, FILE *stream);
  705. extern int SystemIsDirectory(char *name);
  706.  
  707.  
  708. #ifdef UNIX
  709. #define UNIX_FILE_SYSTEM
  710. #endif
  711.  
  712. //
  713. // The symbol used in this environment for separating argument in a system string. E.g., in a unix system
  714. // directories specified in the CLASSPATH are separated by a ':', whereas in win95 it is ';'.
  715. //
  716. extern char PathSeparator();
  717. extern int SystemMkdir(char *);
  718. extern int SystemMkdirhier(char *);
  719.  
  720. extern char * strcat3(const char *, const char *, const char *);
  721. extern char * wstring2string(wchar_t * in);
  722.  
  723. //
  724. // Some compilers do not correctly predefine the primitive type "bool"
  725. // and its possible values: "false" and "true"
  726. //
  727. #ifndef HAVE_BOOL
  728. //======================================================================
  729. // We define the type "bool" and the constants "false" and "true".
  730. // The type bool as well as the constants false and true are expected
  731. // to become standard C++. When that happens, these declarations should
  732. // be removed.
  733. //======================================================================
  734. typedef unsigned char bool;
  735. enum { false = 0, true = 1 };
  736. #endif
  737.  
  738. class LongInt;
  739. class ULongInt;
  740. //
  741. //
  742. //
  743. class Ostream
  744. {
  745.     ostream *os;
  746.  
  747.     bool expand_wchar;
  748.  
  749. public:
  750.  
  751.     Ostream() : os(&cerr),
  752.                 expand_wchar(false)
  753.     {}
  754.  
  755.     Ostream(ostream *_os) : os(_os),
  756.                             expand_wchar(false)
  757.     {}
  758.  
  759.     void StandardOutput() { os = &cout; }
  760.     void SetExpandWchar(bool val = true) { expand_wchar = val; }
  761.     bool ExpandWchar() { return expand_wchar; }
  762.  
  763.     Ostream &operator<<(wchar_t ch)
  764.     {
  765.         if (ch >> 8 == 0)
  766.             *os << (char) ch;
  767.         else
  768.         {
  769.             if (expand_wchar == 0)
  770.                 *os << (char) U_QUESTION;
  771.             else
  772.             {
  773.                 *os << (char) U_BACKSLASH
  774.                     << (char) U_u;
  775.  
  776.                 char str[4];
  777.                 for (int i = 3; i >= 0; i--)
  778.                 {
  779.                     int d = ch % 16;
  780.                     switch(d)
  781.                     {
  782.                         case 10:
  783.                             str[i] = U_A;
  784.                             break;
  785.                         case 11:
  786.                             str[i] = U_B;
  787.                             break;
  788.                         case 12:
  789.                             str[i] = U_C;
  790.                             break;
  791.                         case 13:
  792.                             str[i] = U_D;
  793.                             break;
  794.                         case 14:
  795.                             str[i] = U_E;
  796.                             break;
  797.                         case 15:
  798.                             str[i] = U_F;
  799.                             break;
  800.                         default:
  801.                             str[i] = U_0 + d;
  802.                             break;
  803.                     }
  804.                     ch /= 16;
  805.                 }
  806.                 *os << str[0];
  807.                 *os << str[1];
  808.                 *os << str[2];
  809.                 *os << str[3];
  810.             }
  811.         }
  812.  
  813.         return *this;
  814.     }
  815.  
  816.     Ostream &operator<<(const wchar_t *str)
  817.     {
  818.         for (; *str; str++)
  819.             (*this) << *str;
  820.         return *this;
  821.     }
  822.  
  823.  
  824.     Ostream &operator<<(char c)
  825.     {
  826.         *os << c;
  827.         return *this;
  828.     }
  829.  
  830.     Ostream &operator<<(signed char c)
  831.     {
  832.         *os << c;
  833.         return *this;
  834.     }
  835.  
  836.     Ostream &operator<<(unsigned char c)
  837.     {
  838.         *os << c;
  839.         return *this;
  840.     }
  841.  
  842.     Ostream &operator<<(const char *c)
  843.     {
  844.         *os << c;
  845.         return *this;
  846.     }
  847.  
  848.     Ostream &operator<<(const signed char *c)
  849.     {
  850.         *os << c;
  851.         return *this;
  852.     }
  853.  
  854.     Ostream &operator<<(const unsigned char *c)
  855.     {
  856.         *os << c;
  857.         return *this;
  858.     }
  859.  
  860.     Ostream &operator<<(int a)
  861.     {
  862.         *os << a;
  863.         return *this;
  864.     }
  865.  
  866.     Ostream &operator<<(unsigned int a)
  867.     {
  868.         *os << a;
  869.         return *this;
  870.     }
  871.  
  872.     Ostream &operator<<(LongInt);
  873.     Ostream &operator<<(ULongInt);
  874.  
  875.     Ostream &operator<<(float f)
  876.     {
  877.         *os << f;
  878.         return *this;
  879.     }
  880.  
  881.     Ostream &operator<<(double d)
  882.     {
  883.         *os << d;
  884.         return *this;
  885.     }
  886.  
  887.     char fill(char c) { return os -> fill(c); }
  888.  
  889.     Ostream &flush()
  890.     {
  891.         os -> flush();
  892.         return *this;
  893.     }
  894.  
  895.     int width(int w)
  896.     {
  897.         return os -> width(w);
  898.     }
  899.  
  900.     long setf(long setbits)
  901.     {
  902.         return os -> setf(setbits);
  903.     }
  904.  
  905.     Ostream &operator<<(ios &(*f)(ios&))
  906.     {
  907.         (*f)(*os);
  908.         return *this;
  909.     }
  910. };
  911.  
  912. extern Ostream Coutput;
  913.  
  914. //
  915. // From now on, DO NOT USE cout and cerr !!!
  916. //
  917. #define cout Please_Do_Not_Use_cout_Directly_But_use_an_instance_of_Ostream_with_cout_as_argument
  918. #define cerr Please_Do_Not_Use_cerr_Directly_But_use_an_instance_of_Ostream_with_cerr_as_argument
  919.  
  920. #endif // #ifndef config_INCLUDED
  921.